﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="ValuationClient.项目立项.Register" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
     <link href="../jquery-easyui-1.5.2/themes/default/easyui.css" rel="stylesheet" />
    <link href="../jquery-easyui-1.5.2/themes/icon.css" rel="stylesheet" />
    <script src="../jquery-easyui-1.5.2/jquery.min.js"></script>
    <script src="../jquery-easyui-1.5.2/jquery.easyui.min.js"></script>
    <script src="../jquery-easyui-1.5.2/easyloader.js"></script>
</head>
<body>
   <div class="demo-info">
        <div class="demo-tip icon-tip"></div>
    </div>
    <div style="margin: 0;"></div>
    <div class="easyui-panel" fit="true">
        <div style="margin-left: 30px;" id="ff">
            <div>
                <span>借款人员基本信息：</span>
            </div>
            <div style="padding: 10px 0 10px 100px">
                <table>
                    <tbody id="tbtb">
                        <tr>
                            <td><span>借款人员姓名：</span><input class="easyui-textbox name" id="name" type="text" name="name"  /></td>
                            <td><span>身份证号：</span><input class="easyui-textbox card" id="card" type="text" name="idCard"  /></td>
                            <td><span>联系电话：</span><input class="easyui-textbox tel" id="tel" type="text" name="telNumber" /></td>
                            <td><a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',toggle:true" onclick="add()">添加借款人</a></td>
                        </tr>
                    </tbody>
                </table>             
            </div>
            <div>
                <table>
                    <tr>
                        <td>联系人：</td>
                        <td style="padding-left:50px;"><input class="easyui-textbox" id="userName" type="text" name="linkmen"  style="width:800px;" placeholder="请输入联系人"/></td>
                    </tr>
                    <tr>
                        <td>联系电话：</td>
                        <td style="padding-left:50px;"><input class="easyui-textbox" id="userTel" type="text" name="linknumber"  style="width:800px;" placeholder="请输入联系电话，多个电话请用，隔开"/></td>
                    </tr>
                    <tr>
                        <td>房屋剩余年限：</td>
                        <td style="padding-left:50px;"><input class="easyui-textbox" id="surplusYears" type="text" name="overyears"  style="width:800px;" placeholder="请输入房屋剩余年限"/></td>
                    </tr>
                    <tr>
                        <td>贷款额度（万元）：</td>
                        <td style="padding-left:50px;"><input class="easyui-textbox" id="basicQuota" type="text" name="overyears"  style="width:800px;" placeholder="请输入贷款额度，单位为万元"/></td>
                    </tr>
                    <tr>
                        <td>房屋坐落：</td>
                        <td style="padding-left:50px;"><input class="easyui-textbox" id="houseLocated" type="text" name="houseaddr"  style="width:800px;" placeholder="请输入房屋坐落"/></td>
                    </tr>
                    <tr>
                        <td>房屋用途：</td>
                        <td style="padding-left:50px;">
                           <input id="House" name="qysjzt" class="easyui-combobox" style="width:800px;"/>
                        </td>
                    </tr>
                    <tr>
                        <td>建成年代：</td>
                        <td style="padding-left:50px;"><input class="easyui-textbox" type="text"  id="startyear" name="startyear"  style="width:800px;" placeholder="请输入建成年代"/></td>
                    </tr>
                    <tr>
                        <td>建成年代来源：</td>
                        <td style="padding-left:50px;">
                               <input id="completion" name="qysjzt" class="easyui-combobox" style="width:800px;"/>
                        </td>

                    </tr>
                    <tr>
                        <td>报告类型：</td>
                        <td style="padding-left:50px;">
                             <input id="report" name="qysjzt" class="easyui-combobox" style="width:800px;"/>
                        </td>
                    </tr>
                    <tr>
                        <td>评估受理：</td>
                        <td style="padding-left:50px;">
                        <input type="checkbox" class="mm" value="1" />审核评估登记表
                            <input type="checkbox" class="mm" value="2" />身份登记
                            <input type="checkbox" class="mm" value="3" />房屋权属
                            <input type="checkbox" class="mm" value="4" />网签合同
                        </td>
                    </tr>
                    <tr>
                        <td>所属部门：</td>
                        <td style="padding-left:50px;">
                             <input id="Department" name="qysjzt" class="easyui-combobox" style="width:800px;" />
                        </td>
                    </tr>
                    <tr>
                        <td>勘察员：</td>
                        <td style="padding-left:50px;"> <input id="prospectuser" name="qysjzt" class="easyui-combobox" style="width:800px;"/></td>
                    </tr>
                    <tr>
                        <td>估价员：</td>
                        <td style="padding-left:50px;">
                              <input id="evaluate" name="qysjzt" class="easyui-combobox" style="width:800px;"/>
                        </td>
                    </tr>
                    <tr>
                        <td>评估通知单出具日期：</td>
                        <td style="padding-left:50px;"><input id="Cdate" class="easyui-textbox" type="text" name="startyear"  style="width:800px;" placeholder="请输入评估通知单出具日期"/></td>
                    </tr>
                </table>
            </div>
            <div style="text-align: center; padding: 5px">
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="text-align:center;"><span style="position:relative;left:10px;">登</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="position:relative;right:10px;">记</span></a>
            </div>
        </div>
    </div>
    <script>

     
        //添加借款人
        function add() {
            //$("#add").show();
            $("#tbtb").append("<tr><td><span>借款人员姓名：</span><input id=\"name\" class='name' type=\"text\" name=\"name\" /></td><td><span>身份证号：</span><input class='card'  type=\"text\" name=\"idCard\" /></td><td><span>联系电话：</span><input class='tel'  type=\"text\" name=\"telNumber\" /></td><td><a href=\"#\" onclick=\"delperson(this)\">删除借款人</a></td></tr>")
        }
        //删除借款人
        function delperson(obj) {
            $(obj).parent().parent().remove();
        }
    
        //房屋用途
        House();
        function House()
        {
            $.ajax({
                type: "get",
                url: "http://localhost:55439/api/Dictionary?i="+ 1,
                success:function(obj)
                {
                    $('#House').combobox({
                        data: obj,
                        valueField: 'Dictionary_Number',
                        textField: 'dictionary_Name'
                    })
                }
            })
        }

        //建成年代来源
        completion();
        function completion() {
            $.ajax({
                type: "get",
                url: "http://localhost:55439/api/Dictionary?i=" + 2,
                success: function (obj) {
   
                    $('#completion').combobox({
                        data: obj,
                        valueField: 'Dictionary_Number',
                        textField: 'dictionary_Name'
                    })

                }
            })
        }

        //报告类型
        report();
        function report() {
            $.ajax({
                type: "get",
                url: "http://localhost:55439/api/Dictionary?i=" + 3,
                success: function (obj) {

                    $('#report').combobox({
                        data: obj,
                        valueField: 'Dictionary_Number',
                        textField: 'dictionary_Name'
                    })

                }
            })
        }
        
        //所属部门
        Department();
        function Department() {
            $.ajax({
                type: "get",
                url: "http://localhost:55439/api/Department",
                success: function (obj) {
                    $('#Department').combobox({
                        data: obj,
                        valueField: 'Department_Id',
                        textField: 'Department_Name'
                    })
                }
            })
        }

        //根据所选择的部门分别获取到相对应的勘察员 估价员
        $("#Department").combobox({
            onChange: function (newValue) {
                prospectuser(newValue);
                evaluate(newValue);
            }
        });

        //勘查员       
        function prospectuser(newValue) {
            $.ajax({
                type: "get",
                url: "http://localhost:55439/api/department/?id=" + newValue+"&RolesId="+3,
                success: function (obj) {
                    $('#prospectuser').combobox({
                        data: obj,
                        valueField: 'users_Id',
                        textField: 'users_Name'
                    })
                }
            })
        }

        //估价员
        function evaluate(newValue) {
            $.ajax({
                type: "get",
                url: "http://localhost:55439/api/department/?id=" + newValue + "&RolesId=" + 4,
                success: function (obj) {
                    $('#evaluate').combobox({
                        data: obj,
                        valueField: 'users_Id',
                        textField: 'users_Name'
                    })
                }
            })
        }


        //登记信息
        function submitForm()
        {
            var name = "";//获取借款人
            for (var i = 0; i < $(".name").length; i++) {
                name += $(".name").eq(i).val() + ",";
            }
            name = name.substring(0, name.length - 1);

            var card = "";//获取借款人身份证号
            for (var i = 0; i < $(".card").length; i++) {
                card += $(".card").eq(i).val() + ",";
            }
            card = card.substring(0, card.length - 1);

            var tel = "";//获取借款人联系方式
            for (var i = 0; i < $(".tel").length; i++) {
                tel += $(".tel").eq(i).val() + ",";
            }
            tel = tel.substring(0, tel.length - 1);

            var assessment = []; //评估受理
            $(":checkbox:checked").each(function () {
                assessment.push($(this).val());
            })
            var userName = $("#userName").textbox('getValue');//联系人姓名
            var userTel = $("#userTel").textbox('getValue');//联系人电话
            var surplusYears = $("#surplusYears").textbox('getValue');//房屋剩余年限
            var basicQuota = $("#basicQuota").textbox('getValue');//贷款额度
            var houseLocated = $("#houseLocated").textbox('getValue');//房屋坐落
            var House = $("#House").combobox('getValue')//房屋用途
            var startyear = $("#startyear").textbox('getValue');//建成年代
            var completion = $("#completion").combobox('getValue')//建成年代来源
            var report = $("#report").combobox('getValue')//报告类型
            var Department = $("#Department").combobox('getValue')//所属部门
            var prospectuser = $("#prospectuser").combobox('getValue')//勘察员
            var evaluate = $("#evaluate").combobox('getValue')//估价员
            var Cdate = $("#Cdate").textbox('getValue');//出具日期

            $.ajax({
                type: "post",
                url: "http://localhost:55439/api/Project?name=" + name + "&card=" + card + "&tel=" + tel + "&userName=" + userName + "&userTel=" + userTel,
                data: {

                    surplus_Years: surplusYears, basic_Quota: basicQuota, house_Located: houseLocated,
                    house_Purpose: House, house_Time: startyear, yers_Source: completion, presentation_Type: report,
                    assessment: assessment.toString(), the_Department: Department, survey: prospectuser,
                    evaluation: evaluate, issue_Time: Cdate
                   },
               
                success:function(result)
                {
                    if(result>0)
                    {
                        $.messager.alert('消息', '登记成功');
                    }
                    else
                    {
                        $.messager.alert('消息', '登记失败');
                    }
                }
            })


            
            



    
        }


    </script>
</body>
</html>
